package com.neusoft.cmsprojects.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;

@Entity
public class Privilege implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer id;
	private String name;
	private String url;
	//多对多的关系
	private Set<Role> role=new HashSet<Role>();
	private Privilege parent;
	private Set<Privilege> children=new HashSet<Privilege>();
	
	public Privilege() {
	}
	
	public Privilege(String name, String url, Privilege parent) {
		this.name = name;
		this.url = url;
		this.parent = parent;
	}

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	
	@ManyToMany(mappedBy="privilege",fetch=FetchType.EAGER)
	public Set<Role> getRole() {
		return role;
	}

	public void setRole(Set<Role> role) {
		this.role = role;
	}

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="parentid")
	public Privilege getParent() {
		return parent;
	}

	
	public void setParent(Privilege parent) {
		this.parent = parent;
	}
	
	//本类与孩子的一对多的关系
	@OneToMany(mappedBy="parent",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	public Set<Privilege> getChildren() {
		return children;
	}

	public void setChildren(Set<Privilege> children) {
		this.children = children;
	}
	
	
}
